package com.zhuqieli.database_learn.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import net.coobird.thumbnailator.Thumbnails;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


/**
 * @author xucf-c
 * @data 2023/8/31 16:00
 */
@Component
public class ThumbnailUtils {

    // 对jpg格式文件压缩得到预览图
    public static String generateAndSaveThumbnail(byte[] originalImage, int width, int height, String username, String filename) throws IOException {
        File thumbnailFile = File.createTempFile(username, ".jpg");
        Thumbnails.of(new ByteArrayInputStream(originalImage))
                .size(width, height)
                .toFile(thumbnailFile);
        return thumbnailFile.getAbsolutePath();
    }
}